<template>
  <div class="design-box">
    <div v-loading="loading">
      <nuxt-link to="/"><button> 返 回 首 页 </button></nuxt-link>
      <button @click="$store.commit('login/toggleShow', true)"> 登 录 </button>
    </div>
  </div>
</template>

<script>
export default {
  loading: false,
  asyncData({ query }) {
    return {
      t: query.t,
      loading: false
    };
  },
  middleware: "auth",
  mounted() {
    if (this.$store.state.login.isLogin && localStorage["teamNum"]) {
      this.copyTemplate()
    } else {
      this.$store.commit("login/toggleShow", true);
    }
  },
  methods: {
    // 复制模板
    copyTemplate() {
      this.loading = true
      let n = localStorage["teamNum"];
      let params = `TemplateNumber=${this.t}&TeamNum=${n}`;
      this.$axios.post("/CopyTemplate", params).then(({ data }) => {
        let str = "/designer/" + window.btoa(`DocumentNumber=${data}`);
        console.log(str);
        this.$router.replace(str);
      }).then(res => {
        setTimeout(() => {this.loading = false}, 1000)
      })
    }
  }
};
</script>

<style lang="less">
.design-box {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  button {
      position: relative;
    display: inline-block;
    min-width: 88px;
    height: 36px;
    box-sizing: border-box;
    padding: 0 16px;
    margin: 0;
    overflow: hidden;
    font-size: 14px;
    font-weight: 500;
    line-height: 36px;
    color: inherit;
    text-align: center;
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
    vertical-align: middle;
    cursor: pointer;
    zoom: 1;
    user-select: none;
    background: 0 0;
    border: none;
    border-radius: 2px;
    outline: 0;
    will-change: box-shadow;
    background: linear-gradient(to right,#09AAFF,#62a3ff);
    box-shadow: 0 0 10px 5px #d5e5fb;
    color: #fff;
    }
}
</style>
